#ifndef SRF_H
#define SRF_H

#include <QString>
#include <stdio.h>

using namespace std;

// 16 bytes - string - "GARMIN BITMAP 01"
// 64 bytes - three 32-bit ints, [4, 4, 2] -- purpose unknown
// 7 bytes - PString - "578"
// 8 bytes - PString - version number ("1.00", "2.00", "2.10", or "2.20")
// 16 bytes - PString - "006-D0578-XX" (where "XX" changes) -- I assume this is Garmin's product code?
// 3D Mask info
// 3D Mask data
// 3D Image data
// Top Mask info
// Top Mask data
// Top Image data

class SRF
{

public:
    SRF();
    ~SRF();

    char garmin[32];
    char product[32];
    QString strings[16];

    int nStringCount;
    char tdInfo[256];     // usually either 0x10 or 0x16 bytes
    char topInfo[256];    // usually either 0x10 or 0x16 bytes

    unsigned char* tdMask;          // these 4 buffers depend on image size
    unsigned char* tdRGB;
    unsigned char* topMask;
    unsigned char* topRGB;

    int hdrN1, hdrN2, hdrN3;  // expecting 4, 4, 2 or 4, 4, 4
    int nUnknown1;
    int nSize3DInfo;
    int nSizeTopInfo;

    short tdHeight;
    short tdWidth;
    short topHeight;
    short topWidth;

    int nhexB1;
    int nhexB2;
    int nUnknown2;
    int nUnknown3;
    int nUnknown4;

    int nLen3DMask;
    int nLen3DRGB;
    int nLenTopMask;
    int nLenTopRGB;

    unsigned short chksum;

    char lastErr[256];

    void WriteImages(char* strFilePrefix, unsigned char* buf, unsigned char* mask, short width, short height);
    void Write(const char* strFilePrefix);   // this writes images to 72 files, not a new SRF
                    // write a new SRF file using Create()

    void Read(const char* file);
    unsigned char Checksum(FILE* fSRF);

    void Create(const char* prefix);

    void WriteSRFImage(FILE* fSRF, char* baseFile, unsigned int width, unsigned int height);
    void WriteSRFMask(FILE* fSRF, char* baseFile, unsigned int width, unsigned int height);

    bool CheckFiles(const char* prefix);
};

#endif // SRF_H
